import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/Login.vue'

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    redirect: '/Login',
  },
  {
    path: '/Login',
    name: 'Login',
    component: login
  },
  {
    path: '/main',
    name: 'main',
    component: ()=>import("../views/main"),
    children:[
        { path: '/',
            redirect: '/lease/EC',}
        ,
        {
            path: '/User',
            name: 'User',
            component: ()=>import("../views/system/User")
        },
        {
            path: '/Role',
            name: 'Role',
            component: ()=>import("../views/system/Role")
        },
        {
            name:"menu",
            path:"/menu",
            component: () => import(/* webpackChunkName: "about" */ '../views/system/menu.vue')
        },
        {
            name:"diary",
            path:"/diary",
            component: () => import(/* webpackChunkName: "about" */ '../views/system/diary.vue')
        },
        {
            name:"blank",
            path:"/blank",
            component: () => import(/* webpackChunkName: "about" */ '../blank/blank-diary.vue')
        },
        {
            path: '/EditPassword',
            name: 'EditPassword',
            component: () => import(/* webpackChunkName: "about" */ '../extra/EditPassword.vue')
        },
        {
            path: '/PersonCenter',
            name: 'PersonCenter',
            component: () => import(/* webpackChunkName: "about" */ '../extra/PersonCenter.vue')
        },
      {
        path:'/lease/AllCat',
        name:'AllCat',
        component: ()=>import("../views/lease/AllCat")
        }
        ,
        {
            path:'/lease/CarType',
            name:'CarType',
            component: ()=>import("../views/lease/CarType")
        }
        ,
        {
            path:'/lease/CarConfig',
            name:'CarConfig',
            component: ()=>import("../views/lease/CarConfig")
        },
        {
            path:'/lease/Brand',
            name:'Brand',
            component: ()=>import("../views/lease/Brand.vue")
        },
        {
            path:'/lease/Shop',
            name:'Shop',
            component: ()=>import("../views/lease/Shop")
        }
        ,
        {
            path:'/lease/Comment',
            name:'Comment',
            component: ()=>import("../views/lease/Comment")
        }
        ,
        {
            path:'/lease/EC',
            name:'EC',
            component: ()=>import("../views/lease/EC")
        },{
            path: '/maintain/MaintainRecord',
            name: 'MaintainRecord',
            component: () => import("../views/maintain/MaintainRecord")
        },
        {
            path: '/maintain/MaintainShop',
            name: 'MaintainShop',
            component: () => import("../views/maintain/MaintainShop")
        },
        {
            path:'/market/question',
            name:'Question',
            component: ()=>import("../views/market/Question")
        },{
            path:'/market/advertise',
            name:'Advertise',
            component: ()=>import("../views/market/Advertise")
        },{
            path:'/market/advertisePosition',
            name:'advertisePosition',
            component: ()=>import("../views/market/AdvertisePosition")
        }
        ,
        {
            path: '/Echarts',
            name: 'Echarts',
            component: ()=>import("../components/Echarts")
        },{
            path: '/Echarts2',
            name: 'Echarts2',
            component: ()=>import("../views/company/Operate")
        },
        ,
        {
            path: '/members/client',
            name: 'Client',
            component: ()=>import("../views/members/Client")
        },
        {
            path: '/members/level',
            name: 'Level',
            component: ()=>import("../views/members/Level")
        },
        {
            path: '/members/coupon',
            name: 'Coupon',
            component: ()=>import("../views/members/Coupon")
        },
        {
            path: '/members/points',
            name: 'Points',
            component: ()=>import("../views/members/Points")
        },{
            path: '/members/couponRecord',
            name: 'CouponRecord',
            component: ()=>import("../views/members/CouponRecord")
        }

    ]
  }
]

const router = new VueRouter({
  routes
})

//路由守卫
router.beforeEach((to,from,next)=>{
  var path = to.path;
  if (path==='/login'){
    return next();
  }
  //2.判断是否登录
  let token = sessionStorage.getItem("token");
  if (token){
    return  next();
  }

  //3.跳转到登录
  next("/login");


})

export default router
